package com.cuit.qx.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cuit.qx.bean.SystemConfiguration;
import com.cuit.qx.service.SystemConfigurationService;

/**
 * 系统配置
 * @author Administrator
 *
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/api/systemConfiguration")
@Controller
public class systemConfigurationController {
	
	@Autowired
	private SystemConfigurationService systemConfigurationService;
	
	/**
	 * 系统配置列表
	 * @return
	 */
	@RequestMapping("/list")
	@ResponseBody
	public Map<String, Object> list(){
		List<SystemConfiguration> list=systemConfigurationService.getConfiguration();
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("code", 20000);
        result.put("data", list);

		return result;
	}
	
	/**
	 * 更新系统配置信息
	 * @param systemConfiguration
	 * @return
	 */
	@RequestMapping("/update")
	@ResponseBody
	public Map<String, Object> update(SystemConfiguration systemConfiguration){
		Map<String, Object> map = new HashMap<String, Object>();		
		int update = systemConfigurationService.update(systemConfiguration);
		if(update>0) {
			map.put("success", true);
		}else {
			map.put("success", false);
		}
	    Map<String, Object> result1 = new HashMap<String, Object>();
	    result1.put("code", 20000);
	    result1.put("data", map);
	    return result1;
	}
	
	/**
	 * 删除系统配置信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public Map<String, Object> delete(HttpServletRequest request){
		String id=request.getParameter("id");
		Map<String, Object> map = new HashMap<String, Object>();
		int delete = systemConfigurationService.delete(id);
		if(delete>0) {
			map.put("success", true);
		}else {
			map.put("success", false);
		}
		return map;

	}
	
}
